//
//  DKViewController.swift
//  WebViewJavaScript
//
//  Created by DKHS on 2018/1/10.
//  Copyright © 2018年 CBL. All rights reserved.
//

import UIKit

class DKViewController: UIViewController {

    /// <#注释#>
    fileprivate lazy var backView: UIView = {
        let backView = UIView(frame: CGRect(x: 0, y: 100.0, width: 100, height: 100))
        backView.backgroundColor = UIColor.gray
        return backView
    }()
    
    /// <#注释#>
    fileprivate lazy var subButton: UIButton = {
        let subButton = UIButton(frame: CGRect(x: 20, y: 20, width: 50, height: 50))
        subButton.setTitle("点我", for: .normal)
        subButton.backgroundColor = UIColor.blue
        subButton.addTarget(self, action: #selector(didClickSubButton), for: .touchUpInside)
        return subButton
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.addSubview(backView)
        backView.addSubview(subButton)
        subButton.autoresizingMask = [.flexibleLeftMargin, .flexibleTopMargin]
    }
    
    @objc fileprivate func didClickSubButton() {
        NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(action), object: nil)
        perform(#selector(action))
    }
    
    @objc fileprivate func action() {
        DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {[weak self] in
            if let frame = self?.backView.frame {
                self?.backView.frame = CGRect(x: frame.origin.x, y: frame.origin.y, width: frame.size.width + 10, height: frame.size.height + 10)
            }
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
